<template>
	<view class="container">
		<!-- 		<u-navbar title="安心房源" :autoBack="true" :fixed="true" :bgColor="'#ffffff'" :placeholder="true" :titleStyle="{
				color: '#333',
				fontSize: '16px',
			}"></u-navbar> -->
		<!-- 房源列表 -->
		<view class="house-list">
			<view :key="index" class="house-item" v-for="(item, index) in houseList" @click="selectHouse(item,index)">
				<view class="house-info">
					<image class="house-img" :src="item.avatar" mode="aspectFill"></image>
					<view class="info-content">
						<view class="title">{{ item.username }}</view>
						<view class="room-info">
							<text class="label">发布房源：</text>
							<text class="value">{{ item.count }}</text>
						</view>
						<view class="owner-info"> 
							<text class="label">IP：</text>
							<text class="value">{{ item.community_text }}</text>
						</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="20"></u-icon>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" style="margin-top: 20px;" />
	</view>
</template>

<script>
	import {
		getSafeHouseUser
	} from '@/api/houseresources.js'
	import {
		getArea,
		getTagList
	} from '@/api/gent.js'
	import {
		getHouseOptionList
	} from '@/api/mine.js'
	export default {
		data() {
			return {
				status: 'loadmore',
				queryparams: {
					page: 1,
					page_size: 10
				},
				houseList: [],
				selectedHouse: null,
			};
		},
		onLoad(e) {
			this.queryparams.community = e.community
			this.getList();
		},
		methods: {
			getList() {
				getSafeHouseUser(this.queryparams).then((res) => {
					this.houseList = res.data.data.data;
					// 更新状态
					this.status = this.houseList.length < this.queryparams.page_size ? 'nomore' : 'loadmore';
					uni.stopPullDownRefresh(); // 停止下拉刷新
				})
			},
			// 下拉刷新
			onPullDownRefresh() {
				this.queryparams.page = 1; // 重置为第一页
				this.houseList = []; // 清空当前列表数据
				this.getList(); // 请求第一页数据
			},
			//上拉加载
			onReachBottom() {
				console.log('Reached bottom. Status:', this.status);
				if (this.status === 'loading' || this.status === 'nomore') return;
				this.status = 'loading';
				this.queryparams.page++; // 增加当前页码
				this.getList();
			},
			selectHouse(item, index) {
				this.selectedHouse = index;
				uni.navigateTo({
					url: '/pages-house/safe-house-list/safe-house-list?details=' + JSON.stringify(item)
				});
			}
		}
	};
</script>

<style lang="less" scoped>
	.container {
		min-height: 100vh;
		background-color: #f5f6fa;
	}

	.house-list {
		padding: 24rpx;

		.house-item {
			background: #fff;
			border-radius: 12rpx;
			padding: 24rpx;
			margin-bottom: 24rpx;
			transition: all 0.2s;

			&.active {
				background-color: #e2f0ff;
			}

			.house-info {
				display: flex;

				.house-img {
					width: 160rpx;
					height: 160rpx;
					border-radius: 8rpx;
					margin-right: 24rpx;
				}

				.info-content {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					flex: 1;

					.title {
						font-size: 26rpx;
						font-weight: 500;
						color: #222222;
					}

					.room-info,
					.owner-info {
						font-size: 26rpx;

						.label {
							color: #222;
						}

						.value {
							color: #999;
						}
					}
				}
			}
		}
	}
</style>